<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<style type="text/css">
			html,
			body {
				height: 100%;
				width: 100%;
				margin: 0px;
				padding: 0px;
			}

			#bcid {
				background: #0F0;
				height: 100%;
				width: 100%;
			}
		</style>
	</head>

	<body>
		<body>
			<!--指定Barcode对象的在界面中关联div标签的id号。-->
			<div id="bcid">

			</div>
		</body>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript">
			var backId;
			var qrcode;
			var scan;
			mui.init({
				beforeback: function() {
					//关闭扫描控件
					if (scan) {
						scan.close();
					}
					//获得调用二维码扫描的界面
					var list = plus.webview.getWebviewById(backId);
					//触发调用二维码扫描界面的scaned事件,处理二维码扫描结果
					mui.fire(list, 'scaned', {
						qrcode: qrcode
					});

					plus.webview.currentWebview().close();
					//返回true，继续页面关闭逻辑
					return true;
				}
			})

			mui.plusReady(plusReady);

			function plusReady() {
				// 获取窗口对象  
				backId = plus.webview.currentWebview().backId;
				// 创建扫描控件 
				scan = new plus.barcode.Barcode('bcid', {
					top: '100px',
					left: '0px',
					width: '100%',
					height: '500px',
					position: 'static'
				});
				// 定义识别成功事件  
				scan.onmarked = onmarked;
				// 开始扫描  
				scan.start();
			}

			// 二维码扫描成功  
			function onmarked(type, result, file) {
				switch (type) {
					case plus.barcode.QR:
						type = 'QR';
						break;
					case plus.barcode.EAN13:
						type = 'EAN13';
						break;
					case plus.barcode.EAN8:
						type = 'EAN8';
						break;
					default:
						type = '其它' + type;
						break;
				}
				//result = result.replace(/\n/g, '');
				qrcode = result;
				mui.back();
			}
		</script>
	</body>

</html>
